package com.swing.thread;

import base.RunnableBase;
import com.swing.gui.APP;
import com.swing.gui.component.MiniTray;

import javax.swing.*;

/**
 * @author Yuang, Gongming
 * @date 2022-01-18 10:42
 */
public class TrayFlash extends RunnableBase {

    public static volatile boolean isStop;
    private static TrayFlash trayFlash;

    private TrayFlash() {
    }

    public static TrayFlash init() {
        //  默认不开启
        return init(isStop);
    }

    /**
     * 线程默认开启
     * @param flag 标记：开启
     * @return 自定义，线程任务！（唯一）
     */
    public static TrayFlash init(boolean flag) {
        isStop = flag;
        if (trayFlash == null) {
            synchronized (TrayFlash.class) {
                if (trayFlash == null) {
                    trayFlash = new TrayFlash();
                }
            }
        }
        return trayFlash;
    }

    @Override
    public void execute() throws Exception{
        System.out.println("WARNING -（图标闪烁效果）线程开启……" + System.currentTimeMillis());
        while (isStop) {
            //  todo - 图标闪烁效果
            MiniTray.init().setImage(new ImageIcon("").getImage());
            Thread.sleep(200);

            MiniTray.init().setImage(APP.init().getIconImage());
            Thread.sleep(300);

            //  todo - 获取实时数据（……）

        }
        System.out.println("WARNING -（图标闪烁效果）线程结束……" + System.currentTimeMillis());
    }

}
